home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoBtOv.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.9 KB  |  171 lines

  1. /*
  2.  *   $RCSfile: undoBtOv.C,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "BTREEPAGE.h"
  38. #include "OVPAGE.h"
  39. #include "BT_Log.h"
  40. #ifdef INIT_LRC_IS_LSN
  41. #   include "log_globals.h"
  42. #   include "undo_extfuncs.h"
  43. #endif
  44.  
  45. #ifdef DEBUG
  46. int undoBtOvTrace = FALSE;
  47. #undef BT_TRACE
  48. #define BT_TRACE(x)  { if (undoBtOvTrace)  printf x; }
  49. #else
  50. #define BT_TRACE(x)
  51. #endif DEBUG
  52.  
  53. void undoBtOv(LOGRECORDHDR* recHdr)
  54. {
  55. #ifdef INIT_LRC_IS_LSN
  56.     LRC                 tempLRC;
  57.     LRC                 *lrc = &tempLRC;
  58. #else
  59.     TRANSREC* transRec = (TRANSREC*) Active->transRec;
  60.     INIT_MISSING_UPDATE_INFO(transRec);
  61.  
  62.     LRC                 *lrc;
  63. #endif /* INIT_LRC_IS_LSN; */
  64.  
  65.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recHdr->recordLSN));
  66.  
  67.     PID* pid = &recHdr->actionPid;
  68.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  69.  
  70.     GROUPLINK* groupLink = bf_ReadPage(UserBufGroup, pid, 
  71.                                         BTREE_PAGE2SIZE, BF_SEM);
  72.     OVPAGE* op = (OVPAGE*) groupLink->bufFrame;
  73.  
  74.     BOOL actionDone = compareLRC( &recHdr->actionLRC, &(op->lrc())) <= 0;
  75.  
  76. #ifndef INIT_LRC_IS_LSN
  77.     ASSERT3(missingUpdateInfo != NULL);
  78. #endif INIT_LRC_IS_LSN
  79.  
  80.     RECORD_MISSING_UPDATE( actionDone, &lrc, missingUpdateInfo, pid,
  81.                 &op->lrc(), groupLink->pageHash, recHdr, PAGE_INDEX);
  82.  
  83.  
  84.     if (lrc != & op->lrc())        GENERATE_LRC(lrc);
  85.  
  86.     LSNOFFSET undoNextLSN = recHdr->previousLSN;
  87.  
  88.     signalSemaphore( & groupLink->pageHash->semaphore);
  89.  
  90.     void* vptr = GET_LOG_IMAGE(recHdr, 0);
  91.     PAGEHASH* pHash = actionDone ? groupLink->pageHash : 0;
  92.     
  93.     switch (recHdr->action)  {
  94.         case LOG_ACTION_BTOV_MODIFY_NEXT_LINK:
  95.             {
  96.             LogBtOvModifyNextLink* rp = (LogBtOvModifyNextLink*) vptr;
  97.             BT_TRACE(("U: btov modify next (%d)\n", pid->page));
  98.             if (actionDone) {
  99.                 ASSERT3(op->NextPage() == rp->newNext);
  100.                 op->NextPage() = rp->oldNext;
  101.                 }
  102.             OV_LogModifyNextLink(op->SelfID(), pHash, *lrc,
  103.                         rp->rootPid, rp->newNext, rp->oldNext, undoNextLSN);
  104.             }
  105.             break;
  106.             
  107.         case LOG_ACTION_BTOV_MODIFY_PREV_LINK:
  108.             {
  109.             LogBtOvModifyPrevLink* rp = (LogBtOvModifyPrevLink*) vptr;
  110.             BT_TRACE(("U: btov modify prev (%d)\n", pid->page));
  111.             if (actionDone) {
  112.                 ASSERT3(op->PrevPage() == rp->newPrev);
  113.                 op->PrevPage() = rp->oldPrev;
  114.                 }
  115.             OV_LogModifyPrevLink(op->SelfID(), pHash, *lrc,
  116.                         rp->rootPid, rp->newPrev, rp->oldPrev, undoNextLSN);
  117.             }
  118.             break;
  119.             
  120.         case LOG_ACTION_BTOV_INSERT:
  121.             {
  122.             LogBtOvInsert* rp = (LogBtOvInsert*) vptr;
  123.             BT_TRACE(("U: btov insert (%d)\n", pid->page));
  124.             ASSERT3(rp->numSlots > 0);
  125.             ASSERT3(rp->startSlot >= 0);
  126.             
  127.             OV_LogDelete(op->SelfID(), pHash, *lrc,
  128.                     rp->rootPid, rp->elSize, 
  129.                     rp->startSlot, rp->numSlots, rp->data, undoNextLSN);
  130.             if (actionDone)
  131.                 op->Remove(rp->startSlot, rp->numSlots);
  132.             }
  133.             break;
  134.  
  135.         case LOG_ACTION_BTOV_DELETE:
  136.             {
  137.             LogBtOvDelete* rp = (LogBtOvDelete*) vptr;
  138.             BT_TRACE(("U: btov delete (%d)\n", pid->page));
  139.             
  140.             ASSERT3(rp->numSlots > 0);
  141.             ASSERT3(rp->startSlot >= 0);
  142.             
  143.             if (actionDone) 
  144.                 op->Insert(rp->startSlot, rp->numSlots, rp->data);
  145.  
  146.             OV_LogInsert(op->SelfID(), pHash, *lrc,
  147.                     rp->rootPid, rp->elSize,
  148.                      rp->startSlot, rp->numSlots, rp->data, undoNextLSN);
  149.             }
  150.             break;
  151.             
  152.         default:
  153.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  154.         }
  155. #ifdef BT_DEBUG
  156.     switch (recHdr->action)  {
  157.         case LOG_ACTION_BTOV_MODIFY_NEXT_LINK:
  158.         case LOG_ACTION_BTOV_MODIFY_PREV_LINK:
  159.             ASSERT3(op->CheckPage());
  160.             break;
  161.                 
  162.         case LOG_ACTION_BTOV_INSERT:
  163.         case LOG_ACTION_BTOV_DELETE:
  164.             ASSERT3(op->CheckPage());
  165.             break;
  166.         }
  167. #endif  /* BT_DEBUG */
  168.     
  169.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  170. }
  171.